﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WxxMail.Common;
using WxxMail.DAO;
using WxxMail.Domain;
using WxxMail.IBLL;
using WxxMail.IDAO;

namespace WxxMail.BLL
{
    public partial class AnswerService : BaseService<Answer>,IAnswerService
    {
        /// <summary>
        /// 获取需要编辑的Answer
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Answer GetEditAnswer(int id)
        {
            using (ArticleEntities articleEntities = new ArticleEntities())
            {
                //var query = articleEntities.Answer
                //    .Where(p => p.AnswerId == id.ToString())
                //    .Select(p => new
                //    {
                //        p.AnswerContent,
                //        p.AnswerId,
                //        p.BestNum
                //    }).SingleOrDefault();
                String strid = id.ToString();
                return articleEntities.Answer.Where(u => u.AnswerId == strid).FirstOrDefault();
              
            }
           

        }

        //public static List<Answer> GetList(int posid)
        //{
        //    //return _dbSession.AnswerDAO.LoadEntites(u=>u.adid==posid).FirstOrDefault();
        //    ArticleEntities model = new Domain.ArticleEntities();
        //    var result = (from p in model.Answer
        //                  select p).ToList();
        //    List<Answer> bans = new List<Answer>();
        //    bans = result;
        //    return bans;
        //}
        public virtual IList<Answer> GetList(AnswerRequest request)
        {
            //var model = _newsModelFactory.PrepareHomePageNewsItemsModel();
            //return PartialView(model);
            request = request ?? new AnswerRequest();

            using (var dbContext = new ArticleEntities())
            {
                IQueryable<Answer> users = dbContext.Answer;

                return users.OrderByDescending(u => u.AnswerId).ToPagedList(request.PageIndex, request.PageSize);
            }                
        }

        public void SaveEdit(Answer answer)
        {
            AnswerService _answerService = new AnswerService();
            _answerService.UpdateEntity(answer);

    }
        //public void AddAnswer(Answer answer)
        //{
        //    if (answer == null)
        //        throw new ArgumentNullException("answer");

        //    AnswerService _answerService = new AnswerService();
        //    _answerService.AddEntity(answer);
        //}

    }
}
